package com.test;

import com.bean.Dao.UserMapper;
import com.bean.User;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.InputStream;
import java.util.List;

public class UserTest5 {
    @Test
    public void test01() throws Exception {
        InputStream is = Resources.getResourceAsStream("MyBatisConfig.xml");
        SqlSessionFactory ssf = new SqlSessionFactoryBuilder().build(is);
        SqlSession ss = ssf.openSession(true);

        UserMapper mapper = ss.getMapper(UserMapper.class);

        PageHelper.startPage(2,4);
        List<User> userList = mapper.findAllResultMap();
        for(User user :userList){
            System.out.println(user);
        }
        PageInfo<User> userPageInfo = new PageInfo<>(userList);
        //总条数
        System.out.println("总条数"+userPageInfo.getTotal());
        //总页数
        System.out.println("总页数"+userPageInfo.getPages());
        //每页条数
        System.out.println("每页条数"+userPageInfo.getPageSize());

    }
}
